<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MELANGE.
 *
 * PHP-MELANGE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MELANGE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MELANGE; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-melange
 * @subpackage  cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */
?>
<?=$this->header()?>


    <?=$this->menu("images")?>


    <h1><?=$this->message("label.header", _Image::BUNDLE)?></h1>


    <? /* Breadcrums route & page info display */ ?>
    <?=$this->route(
        $this->message("label.header", _Image::BUNDLE),  // Route display
        $this->imageListForm,                           // ListForm (for page info, see float right)
        $this->images($this->imageListForm)->getRows()  // The total amount of pages
    )?>

    <? /* Show status messages */ ?>
    <?=$this->messages(_Core::BUNDLE)?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null, _Core::BUNDLE)?>


    <form id="<?=get_class($this->imageListForm)?>"
          method="post"
          action="image/list"
          onsubmit="return confirmDelete('<?=$this->message("message.confirm.delete", _Core::BUNDLE)?>', this)">


        <? /* Show the Search & Filter Panel */ ?>
        <?=$this->panel(
            "image/edit",                // Add New URL
            $this->imageListForm,                      // ListForm
            array(                                     // Filter fields
                BinaryFilePeer::FILE_NAME=>$this->message("file.filename", _Core::BUNDLE),
                ImagePeer::SECURE=>$this->message("label.secure", _Image::BUNDLE),
                ImagePeer::INSERT_DATE=>$this->message("choose.created", _Core::BUNDLE),
                ImagePeer::MODIFIED_DATE=>$this->message("choose.modified", _Core::BUNDLE)
            ),false                                    // No languages select-box.
        )?>


        <? /* Start output buffering in case there are no results */ ?>
        <?$this->start()?>


        <table  cellspacing="0" cellpadding="0" class="list">
        <tr>
            <th class="checkbox"></th>
            <th class="narrow"><?=$this->message("label.item", _Image::BUNDLE)?></th>
            <th>
                <?=$this->TH(
                    $this->imageListForm,                         // ListForm
                    BinaryFilePeer::FILE_NAME,                 // Sort Field
                    $this->message("file.filename", _Core::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->imageListForm,                         // ListForm
                    BinaryFilePeer::FILE_SIZE,                 // Sort Field
                    $this->message("file.filesize", _Core::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->imageListForm,                         // ListForm
                    ImagePeer::SECURE,                         // Sort Field
                    $this->message("label.secure", _Image::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->imageListForm,                           // ListForm
                    ImagePeer::MODIFIED_DATE,                    // Sort Field
                    $this->message("choose.modified", _Core::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->imageListForm,                          // ListForm
                    ImagePeer::INSERT_DATE,                     // Sort Field
                    $this->message("choose.created", _Core::BUNDLE) // Header Name
                )?>
            </th>
            <th class="buttons"></th>
        </tr>

        <? foreach($this->images($this->imageListForm)->getItems() as $image): ?>

            <tr class="ctrl">
                <td class="checkbox">
                    <input type="checkbox"
                           name="items[]"
                           value="<?=$image->getTinyImageId()?>"
                           <?=in_array($image->getTinyImageId(), $this->imageListForm->getItems()) ? " checked=\"checked\"" : ""?> />
                </td>
                <td><a href="image?id=<?=$image->getImageId()?>"><?=$this->thumbnail($image->getThumbnailId())?></a></td>
                <td><?=$this->truncateNicely($image->getImageRelatedByImageId()->getBinaryFile()->getFileName(), 30, 38, "...")?></td>
                <td><?=$image->getImageRelatedByImageId()->getBinaryFile()->getHumanReadableFileSize()?></td>
                <td><?=$this->message("label." . ($image->getImageRelatedByImageId()->getSecure() ? "yes" : "no"), _Core::BUNDLE)?></td>
                <td title="<?=$this->message("title.modified", _Core::BUNDLE)?> <?=$image->getImageRelatedByImageId()->getModifiedDate(_Core::FORMAT_DATETIME)?>">
                    <?=$image->getImageRelatedByImageId()->getModifiedDate(_Core::FORMAT_DATE)?>
                </td>
                <td title="<?=$this->message("title.created", _Core::BUNDLE)?> <?=$image->getImageRelatedByImageId()->getInsertDate(_Core::FORMAT_DATETIME)?>">
                    <?=$image->getImageRelatedByImageId()->getInsertDate(_Core::FORMAT_DATE)?>
                </td>
                <td class="buttons">

                    <input type="button"
                           onclick="to('image/edit?tinyImage->tinyImageId=<?=$image->getTinyImageId()?>')"
                           class="button"
                           value="<?=$this->message("button.edit", _Core::BUNDLE)?>" />
                    <input type="button"
                           onclick="del(<?=$image->getTinyImageId()?>, '<?=get_class($this->imageListForm)?>')"
                           class="button"
                           value="<?=$this->message("button.delete", _Core::BUNDLE)?>" />

                </td>
            </tr>

        <? endforeach; ?>

        </table>


        <? /* Edit/Action Bar for checkboxed */ ?>
        <?=$this->edit(
            $this->imageListForm, // ListForm
            array(                // The actions
                "delete"=>$this->message("choose.delete", _Core::BUNDLE)
            )
        )?>


        <? /* End output buffering */ ?>
        <?$this->end(
            $this->imageListForm,
            "image/edit",
            $this->images($this->imageListForm)->getRows()
        )?>


    </form>

<?=$this->footer()?>